package com.sgb.kjwl.viewmodel.enterprise;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.enterprise.MyNeedQuoteDatailEntity;
import com.swgk.core.base.model.entity.BaseEntity;

import org.jetbrains.annotations.NotNull;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MySignUpDetailViewModel extends AndroidViewModel {
    public MutableLiveData<String> toastUntil = new MutableLiveData<>();
    public MutableLiveData<Integer> showLoading = new MutableLiveData<>();
    public MutableLiveData<MyNeedQuoteDatailEntity> dateDetail = new MutableLiveData<>();//详情
    public String xqid = "";

    public MySignUpDetailViewModel(@NonNull @NotNull Application application) {
        super(application);
    }

    public void getDetails(String xqid, String bjid) {
        this.xqid = xqid;
        showLoading.postValue(1);
        APIManager.getInstance().getNeedAPI().getQuotationData(xqid, bjid).enqueue(new Callback<BaseEntity<MyNeedQuoteDatailEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<MyNeedQuoteDatailEntity>> call, Response<BaseEntity<MyNeedQuoteDatailEntity>> response) {
                showLoading.postValue(2);
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    dateDetail.postValue(response.body().getData());
                } else {
                    toastUntil.postValue(response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<MyNeedQuoteDatailEntity>> call, Throwable t) {
                showLoading.postValue(2);
                toastUntil.postValue(t.getMessage());
            }
        });
    }
}
